import os,sys

HTTPSTART = 'http://'
FILESTART = 'file://'
SILLY_URL_START='${userspace}'
WIN_LEADING = 'Z:'

def file_to_path(user,subs):
    if sys.platform.startswith('win'):
        p = os.path.sep.join(subs.split('/'))
        p = WIN_LEADING + p
        return p
    elif sys.platform.startswith('linux'):
        if subs.startswith('/root') or subs.startswith('/home'):
            return "\"" + subs + "\""
        if user == 'root':
            return "\"" + '/'.join(['/root',subs]) + "\""
        else:
            return "\"" + '/'.join(['/home',user,subs]) + "\""
    else: return ''
    
def url_to_path(user,url):
    return url

def map_url(user,url):
    if url == None or len(url.strip())== 0:
        return ''
    
    if url.startswith(HTTPSTART):
        return url_to_path(user,url)
#    elif url.startswith(FILESTART):
#        subs = url[len(FILESTART):]
#        p = file_to_path(user,subs)
#        return p
    elif url.startswith(SILLY_URL_START):
        subs = url[len(SILLY_URL_START):]
        p = file_to_path(user,subs)
        return p
    else:
        return url